﻿
Public Class FileNode
    Inherits KryptonTreeNode
    Implements ISettable
    'Ctor :
    Public Sub New(ByVal filepath As String)
        MyBase.New()
        Control.CheckForIllegalCrossThreadCalls = False
        _Size = New IO.FileInfo(filepath).Length
        _SourcePath = filepath
        Me.Text = IO.Path.GetFileName(_SourcePath)
        Me.LongText = StringFromSize(_Size)
        Dim ext As String = IO.Path.GetExtension(filepath)
        Me.ImageKey = ext
        Me.SelectedImageKey = ext
        _EntrySettings = New EntrySettings
    End Sub
    'Fields :
    Private _Size As Long
    Public ReadOnly Property Size As Long
        Get
            Return _Size
        End Get
    End Property
    Private _SourcePath As String
    Public ReadOnly Property SourcePath As String
        Get
            Return _SourcePath
        End Get
    End Property
    Public ReadOnly Property ZipPath As String
        Get
            Dim zpath As String = ""
            If TypeOf Me.Parent Is ZipNode Then
                zpath = ""
            Else
                Dim currnode As KryptonTreeNode = Me
                While TypeOf currnode.Parent Is FolderNode
                    zpath.Insert(0, currnode.Parent.Text & "\")
                    currnode = CType(currnode.Parent, KryptonTreeNode)
                End While
            End If
            Return zpath
        End Get
    End Property
    Public ReadOnly Property FullZipPath As String
        Get
            Return Me.ZipPath & "\" & IO.Path.GetFileName(_SourcePath)
        End Get
    End Property
    'Delete :
    Public Function Delete() As String
        Dim path As String = Me.SourcePath
        If Me.Parent IsNot Nothing Then
            CType(Me.Parent, IContainable).UpdateSize(-1L * Me.Size)
            Me.Remove()
        End If
        Return path
    End Function
    'Entry Settings :
    Private _EntrySettings As EntrySettings
    Public ReadOnly Property EntrySettings As EntrySettings Implements ISettable.EntrySettings
        Get
            Return _EntrySettings
        End Get
    End Property
    'Inherit Parent Entry Settings :
    Public Sub InheritEntrySettings() Implements ISettable.InheritEntrySettings
        Dim com As String = Me.EntrySettings.Comment
        If Me.Parent IsNot Nothing Then
            If TypeOf Me.Parent Is FolderNode Then
                Me.EntrySettings.CopyFrom(CType(Me.Parent, FolderNode).EntrySettings)
            ElseIf TypeOf Me.Parent Is ZipNode Then
                Me.EntrySettings.CopyFrom(CType(Me.Parent, ZipNode).ZipSettings.MakeEntrySettings)
            End If
        End If
        Me.EntrySettings.Comment = com
    End Sub
End Class